package com.markc1d.weibo.controller;

import com.markc1d.weibo.mapper.HotNewsMapper;
import com.markc1d.weibo.pojo.entity.HotNews;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping
public class HotNewsController {

    @Autowired
    HotNewsMapper hotNewsMapper;

    @GetMapping("/HotNewsArr")
    public List<HotNews> HotNewsArr() {
        return hotNewsMapper.HotNewsArr();
    }

    @GetMapping("admin/HotNewsArr")
    public List<HotNews> AdminHotNewsArr() {
        return hotNewsMapper.HotNewsArr();
    }

    // 删除热搜
    @DeleteMapping("/admin/deleteHotNews/{id}")
    public int deleteHotNews(@PathVariable("id") Integer id) {
        hotNewsMapper.deleteTitleById(id);
        return 1;
    }

    // 更新热搜
    @PutMapping("/admin/updateHotNews/{id}")
    public int updateHotNews(@PathVariable("id") Integer id, @RequestBody HotNews hotNews) {
        // 这里假设 hotNewsMapper 有一个 updateTitleById 方法，你需要根据你的实际情况调整这部分
        hotNewsMapper.updateTitleById(hotNews.getId(), hotNews.getTitle());
        return 1; // 返回 1 表示更新成功
    }

}
